package org.example.memora.store;

import dev.langchain4j.store.memory.chat.ChatMemoryStore;
import org.example.memora.store.MongoChatMemoryStore;
import org.example.memora.store.MongoChatMemoryStoreJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import  dev.langchain4j.data.message.ChatMessage;


import java.util.List;

@Component("dualChatMemoryStore")
public class DualChatMemoryStore implements ChatMemoryStore {

    @Autowired
    private MongoChatMemoryStoreJson mongoChatMemoryStoreJson;
    // 支持 Function Calling 的 JSON 存储

    @Autowired
    private MongoChatMemoryStore mongoChatMemoryStore;
    // 支持分页查询的文档存储

    @Override
    public List<ChatMessage> getMessages(Object memoryId) {
        // 主用 Function Calling 兼容的消息源
        return mongoChatMemoryStoreJson.getMessages(memoryId);
    }

    @Override
    public void updateMessages(Object memoryId, List<ChatMessage> messages) {
        mongoChatMemoryStoreJson.updateMessages(memoryId, messages);
        mongoChatMemoryStore.updateMessages(memoryId, messages);
    }

    @Override
    public void deleteMessages(Object memoryId) {
        mongoChatMemoryStoreJson.deleteMessages(memoryId);
        mongoChatMemoryStore.deleteMessages(memoryId);
    }
}
